package com.yequan.regex;

/**
 * @author yequan
 * @date 2020/12/14 14:25
 **/
public class RegexDemo {

    public static void main(String[] args) {
        String str = "北京湖广会馆地位置";
        String uuuuu = str.replaceAll("....$", "uuuuu");
        System.out.println(uuuuu);


        String s = operateShortAddress(str);
        System.out.println(s);

        String s1 = operateShortAddress("长江人文");
        System.out.println(s1);

        String s2 = operateShortAddress("江西省赣州市章贡区蓉江新区");
        System.out.println(s2);
    }

    private static String operateShortAddress(String shortAddress){
        if (shortAddress.length() > 8){
            int replaceLength = shortAddress.length() - 8;
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < replaceLength; i++) {
                stringBuilder.append(".");
            }
            stringBuilder.append("$");
            shortAddress = shortAddress.replaceAll(stringBuilder.toString(), "...");
        }
        return shortAddress;
    }

}
